/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import ModeratorOperations.ModeratorManageUser;
import beans.SuspendUserBean;
import beans.UserType;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import xmlMapping.Member;
import xmlMapping.Suspend;

/**
 *
 * @author sh
 */
public class SusPendUserAction extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
   // private static final String SUCCESS = "success";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        String find;

                UserType type=(UserType)request.getSession().getAttribute("type");
                if(type==null||(!type.equals(UserType.adm)&&!type.equals(UserType.mod)&&!type.equals(UserType.supermod))){
                    find="login";
                }else{
                    Integer modid=(Integer)request.getSession().getAttribute("id");
                    int mid=Integer.parseInt(request.getParameter("mid"));
                    String reason=((SuspendUserBean)form).getReason();
                    String expireDate=((SuspendUserBean)form).getExpireDate();
                    String[] expired=((SuspendUserBean)form).getExpired();//expireDate.split("-");
                    //System.out.println("xxxxxxxxxxxxxxxxxx"+new Date().toString());
                    ModeratorManageUser modmanage=new ModeratorManageUser();
                    Suspend sus=new Suspend();
                    Member mem=new Member();
                    mem.setMemberId(mid);
                    sus.setMemberByMemberId(mem);
                    Member mod=new Member();
                    mod.setMemberId(modid);
                    sus.setMemberByModId(mod);
                    sus.setReason(reason);
                    sus.setExpiredate(new Date(Integer.parseInt(expired[2])-1900,Integer.parseInt(expired[0])-1,Integer.parseInt(expired[1])));
                //    System.out.println("SuspendUser ::xxxxxxxxxXXXXXXXXXXXXXXXXXXxxxxxxxxx");
                    modmanage.suspendUser(sus);

                    request.setAttribute("threadid", request.getParameter("threadid"));
                    find="success";
                }

                 int pagenumber=Integer.parseInt(request.getParameter("pagenumber"));
                request.setAttribute("pagenumber", pagenumber);
        return mapping.findForward(find);
    }
}
